package com.dahua.utils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 *
 */
public class ThreadPoolService {
    private static ThreadPoolService instance = null;
    private static ExecutorService executorService;

    public static ThreadPoolService getInstance() {
        if (instance == null) {
            instance = new ThreadPoolService();
            executorService = Executors.newFixedThreadPool(5);
        }
        return instance;
    }

    public void submit(Runnable runnable) {
        executorService.submit(runnable);
    }

    public void shutdownAndAwaitTermination() {
        executorService.shutdownNow();
        executorService = null;
        instance = null;
    }
}